<form class="form-horizontal" id="form-review" action="">
    <div id="review"></div>
    <h2>写评论</h2>
    <div class="form-group required">
       <!--  <div class="col-sm-12">
            <label class="control-label" for="input-name">
                姓名                                                                                    </label>
            <input type="text" name="name" value="" id="input-name" class="form-control">
        </div> -->
    </div>
    <div class="form-group required">
        <div class="col-sm-12">
            <label class="control-label" for="input-review">評論</label>
            <textarea name="text" rows="5" id="comment_content" class="form-control"></textarea>
            <div class="text-right"> </div>
            <div class="help-block"></div>
        </div>
    </div>
    <div class="form-group required">
        <div class="col-sm-12">
            <label class="control-label">評級</label>
            &nbsp;&nbsp;&nbsp;
            差&nbsp;
                <input type="radio" name="rating" value="1"> &nbsp;
                <input type="radio" name="rating" value="2"> &nbsp;
                <input type="radio" name="rating" value="3"> &nbsp;
                <input type="radio" name="rating" value="4"> &nbsp;
                <input type="radio" name="rating" value="5"> &nbsp;
                好              
        </div>
    </div>
    <div class="buttons clearfix">
        <div class="pull-right">
            <button type="button" id="comment_submit"  class="btn btn-primary">提交</button>
        </div>
    </div>
</form>
<script type="text/javascript">
    $(function() {
        $("#comment_submit").on('click', function(e) {
            
            const content = $("#comment_content").val();
            const rating = $("input[name='rating']:checked").val();
            console.log(rating)
            if(content) {
                $.ajax({
                    url:"{{ route('goods.comment.store', $goods) }}",
                    data:{
                        content,
                        rating,
                    },
                    type:'post',
                    success:res => {
                        console.log(res)
                        location.reload();
                    },
                    error: res => {

                        console.log(Object.values(res.responseJSON.errors)[0][0]);
                    }
                });
            }
        });
    })
</script>